// pages/subpackage/pages/crm/deviceEdit/deviceEdit.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    screenModeArray: [], //屏幕显示模式
    screenModeIndex: 0,
    filterList: [],
    filterArrey: [{
      filter_index: '',
      parts_name: '',
      residual_value: '',
      cycle: '',
    }],

    equipment_id: '', //缴费器id
    dataInfo: '',
    package_switch:true,
    qrcode_switch:true,
    status_switch:true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      equipment_id: options.equipment_id
    })
    this.getConfigList(); //获取屏幕显示模式列表
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getInfo();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  //获取缴费器详情
  getInfo() {
    var that = this;
    app.ajax({
      url: 'api/Equipmentlists/manageDevice',
      url_type: 2,
      data: {
        id: that.data.equipment_id
      },
      success: function (res) {
        if (res.data.code == 1000) {
          var dataInfo = res.data.data;
          that.setData({
            dataInfo: dataInfo,
          })
          console.log('得到的数组信息',that.data.filterList);
        }
      }
    });
  },


  //开关机
  machineOnOff(e) {
    var that = this;
    var status = e.currentTarget.dataset.state;
    app.ajax({
      url: 'Common/Device/switch_control',
      data: {
        sn: that.data.dataInfo.device_info.device_no,
        device_status: status==1?0:1
      },
      success: function (res) {
        app.showToast(res.data.message, "none", 2000, function () {
          if (res.data.code == 1000) {
            that.setData({
              ['dataInfo.device_info.switch_machine']: status
            })
          }
        });
      }
    })
  },



  // 下发套餐
  setPackage(e){
    var that = this;
    that.setData({
      package_switch:false
    })
    app.ajax({
      url: 'Common/Device/binding_package',
      data: {
        sn: that.data.dataInfo.device_info.device_no,
      },
      success: function (res) {
        app.showToast(res.data.message, "none", 3000, function () {
          that.setData({
            package_switch:true
          })
         });
    
      }
    })
  },

  // 下发二维码
  setQrcode(e){
    var that = this;
    that.setData({
      qrcode_switch:false
    })
    app.ajax({
      url: 'Common/Device/set_qrcode',
      data: {
        sn: that.data.dataInfo.device_info.device_no,
      },
      success: function (res) {
        app.showToast(res.data.message, "none", 3000, function () {
          that.setData({
            qrcode_switch:true
          })
         });
    
      }
    })
  },
    //获取最新状态
    getStatus(e){
      var that = this;
      that.setData({
        status_switch:false
      })
      app.ajax({
        url: 'Equipment/Send/delRedisData',
        data: {
          sn: that.data.dataInfo.device_info.device_no,
        },
        success: function (res) {
          app.showToast(res.data.message, "none", 3000, function () {
            that.setData({
              status_switch:true
            })
           });
      
        }
      })
    },
  

})
